package com.woniu.zsd.shopping.service.impl;

import com.woniu.zsd.shopping.Excel.ReportGenerator;
import com.woniu.zsd.shopping.model.SalesData;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.IOException;

@Service
public class SalesReportServiceImpl {
    @Resource
    private SalesDataServiceImpl salesDataService;

    @Resource
    private ReportGenerator reportGenerator;

    public void generateDailySalesReport() {
        // 从 Redis 获取销售数据
        SalesData salesData = salesDataService.getSalesDataFromRedis();

        if (salesData != null) {
            // 生成 Excel 报表
            try {

//                String outputFilePath = "C:\\Users\\10632\\OneDrive\\Desktop\\报表\\销售报表.xlsx";
//                String outputFilePath = "销售报表.xlsx";
                String outputFilePath = "/opt/dockerzsd/reports/销售报表.xlsx";//改成docker地址
                reportGenerator.generateExcelReport(salesData, outputFilePath);
                System.out.println("报表生成成功！");
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("报表生成失败！");
            }
        } else {
            System.out.println("未从 Redis 获取到销售数据！");
        }
    }
}
